<?php
	$host = "localhost";
	$port = 5432;
	$dbname = "demo";
	$user = "postgres";
	$pass = "pass";
	$thesaurus = "Culture";
	
	if (isset($_GET['query']))
	{
		if ($_GET['query'] == "domains")
		{
			$db = pg_connect("host=$host port=$port dbname=$dbname user=$user password=$pass");
			$resQueryDomaines = pg_query($db, "SELECT get_domains('$thesaurus')");
			if(!$resQueryDomaines) {echo "error"; exit;}
			
			for($i = 0; $i<pg_numrows($resQueryDomaines); $i++) 
			{
					$tabDomaines = pg_fetch_array($resQueryDomaines, $i);
					echo $tabDomaines[0];
					if ($i < pg_numrows($resQueryDomaines)-1)
						echo "*";
			}
			pg_close($db);
		}
		elseif ($_GET['query'] == "concepts")
		{
			if (isset($_GET['domain']))
			{
				$db = pg_connect("host=$host port=$port dbname=$dbname user=$user password=$pass");
				$resQueryConcepts = pg_query($db, "SELECT get_concepts('".$_GET['domain']."');");
				if(!$resQueryConcepts) {echo "error"; exit;}

				for($i = 0; $i<pg_numrows($resQueryConcepts); $i++) 
				{
					$tabConcepts = pg_fetch_array($resQueryConcepts, $i);
					echo $tabConcepts[0];
					if ($i < pg_numrows($resQueryConcepts)-1)
					echo "*";
				}
				pg_close($db);
			}
		}
	}
?>
